<template>
	<view>
		<view>
			<!--公海显示-->
			<view v-if="isGhc" class="bottomBox">
				<view class="tabbarItem" @click="lingquFun">
					<u-icon class="tabImg" size="40" height="40" name="bag"></u-icon>
					<view>领取</view>
				</view>
				<view class="tabbarItem" @click="allotFun">
					<u-icon class="tabImg" size="40" height="40" name="setting"></u-icon>
					<view>分配</view>
				</view>
				<view class="tabbarItem" @click="bianjiFun">
					<u-icon class="tabImg" size="40" height="40" name="edit-pen-fill"></u-icon>
					<view>编辑</view>
				</view>
				<view class="tabbarItem" @click="deleteDataFun">
					<u-icon class="tabImg" size="40" height="40" name="trash"></u-icon>
					<view>删除</view>
				</view>
			</view>
			<!--我的线索-->
			<view v-else class="bottomBox">
				<view class="tabbarItem" v-if="addSheetList.length == 0" @click="genjinFun">
					<u-icon class="tabImg" size="40" name="plus-circle"></u-icon>
					<view>新增跟进</view>
				</view>
				<view class="tabbarItem" v-else @click="sheetShowFun('add')">
					<u-icon class="tabImg" size="40" name="plus-circle"></u-icon>
					<view>新增</view>
				</view>
				<view v-if="isKh" class="tabbarItem" @click="putInFun">
					<u-icon class="tabImg" size="40" height="40" name="download"></u-icon>
					<view>放入线索池</view>
				</view>
				<view class="tabbarItem" @click="bianjiFun">
					<u-icon class="tabImg" size="40" height="40" name="edit-pen-fill"></u-icon>
					<view>编辑</view>
				</view>
				<view class="tabbarItem" @click="deleteDataFun">
					<u-icon class="tabImg" size="40" height="40" name="trash"></u-icon>
					<view>删除</view>
				</view>
			</view>
		</view>
		<u-action-sheet :list="sList" v-model="moreIsShow" @click="sheetClickFun"></u-action-sheet>
		<u-select v-model="allotShow" mode="single-column" confirm-text="确认分配" cancel-text="取消分配" :list="userList"
			@confirm="allotConfirmFun" value-name="id" label-name="realname"></u-select>
	</view>
</template>

<script>
	import {apiClue} from '@/api/crm.js'
	import {apiSysUser} from '@/api/admin.js'
	export default {
		name: "bottomBox",
		props: {
			item: {
				type: Object,
				default: () => {}
			},
			sheetList: {
				type: Array,
				default: () => []
			},
			addSheetList: {
				type: Array,
				default: () => []
			},
			isGhc: {
				type: Boolean,
				default: false
			},
			isKh: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				moreIsShow: false,
				sList: [],
				sheetType: '',
				allotShow: false,
				userList: []
			};
		},
		methods: {
			genjinFun: function() {
				this.$emit('pageGenjinFun')
			},
			sheetClickFun: function(e) {
				if (this.sheetType == 'more') {
					this.$emit('pageMoreIsShowFun', e)
				} else {
					this.$emit('pageAddSheetFun', e)
				}
			},
			bianjiFun: function() {
				this.$emit('pageBianjiFun')
			},
			sheetShowFun: function(str) {
				console.log(str)
				if (str == 'add') {
					this.sList = this.addSheetList;
				} else {
					this.sList = this.sheetList;
				}
				this.sheetType = str;
				this.moreIsShow = true;
			},
			deleteDataFun: function() {
				this.$emit('pageDeleteShowFun')
			},
			// 领取线索
			lingquFun: function() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否确认领取客户名称为：' + that.item.name + '的线索吗?',
					success(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '领取中...',
								mask: true
							})
							let reqData = {
								action: 'goto_personal',
								params: {
									req: {
										id: that.item.id
									}
								}
							}
							apiClue(reqData)
								.then(res => {
									that.$emit('cxPGetDataFun', '领取成功');
									uni.showToast({
										title: '领取成功！',
										duration: 1600,
										icon: 'none',
										mask: true
									})
								})
						}
					}
				})
			},
			// 将线索放入线索池
			putInFun: function() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否确认将客户名称为：' + that.item.name + '的线索放入线索池吗?',
					success(res) {
						let time = new Date().getTime();
						if (res.confirm) {
							uni.showLoading({
								title: '更新中...',
								mask: true
							})
							let reqData = {
								action: 'goto_public',
								params: {
									req: {
										id: that.item.id
									}
								}
							}
							apiClue(reqData)
								.then(res => {
									that.$emit('cxPGetDataFun', '更新成功');
									uni.$emit('updateListByIndex', { index: this.cardIndex, obj: this.khInfo});
									uni.showToast({
										title: '更新成功！',
										duration: 1600,
										icon: 'none',
										mask: true
									})
								})
							
						}
					}
				})
			},
			// 分配线索
			allotFun: function() {
				if (this.userList.length > 0) {
					this.allotShow = true;
				} else {
					this.getSysUserSonsFun();//获得部门用户
				}
			},
			// 分配线索
			allotConfirmFun: function(e) {
				let obj = e[0];
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否确认将客户名称为：' + that.item.name + '的线索分配给 - ' + obj.label + ' - 吗?',
					success(res) {
						let time = new Date().getTime();
						if (res.confirm) {
							uni.showLoading({
								title: '分配中...',
								mask: true
							})
							let reqData = {
								action: 'transfer',
								params: {
									req: {
										id: that.item.id,
										openstatus: 1, // 分配
										owner_user_id: obj.value,//分配给用户id
									}
								}
							}
							apiClue(reqData)
								.then(res => {
									that.$emit('cxPGetDataFun', '分配成功');
									uni.showToast({
										title: '更新成功！',
										duration: 1600,
										icon: 'none',
										mask: true
									})
								})
						}
					}
				})
			},
			// 获取管理用户ids
			getSysUserSonsFun: function() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				let reqData = {
					action: 'get_sys_user_sons',
					params: {
						
					}
				}
				apiSysUser(reqData)
					.then(res => {
						this.userList = res.data;
						this.allotShow = true;
						uni.showToast({
							title: '加载成功！',
							duration: 1600,
							icon: 'none',
							mask: true
						})
					})
			},
		}
	}
</script>

<style>
	.bottomBox {
		width: 100%;
		height: 55px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		background-color: #FFFFFF;
		border-top: 1 rpx solid #DDDDDD;
		font-size: 14px;
	}

	.tabbarItem {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100%;
		padding: 0 36 rpx;
	}

	.tabbarItem:active {
		background-color: #EEEEEE;
	}

	.tabbarItem>.tabImg {
		margin-bottom: 8 rpx;
	}
</style>
